export async function* quickSort(array, compare, swap, set, low = 0, high = array.length - 1) {
    if (low < high) {
        const pivot = array[high];
        let i = low - 1;
        
        for (let j = low; j < high; j++) {
            yield { type: 'compare', indices: [j, high] };
            
            if (await compare(j, high)) {
                i++;
                if (i !== j) {
                    yield { type: 'swap', indices: [i, j] };
                    await swap(i, j);
                }
            }
        }
        
        if (i + 1 !== high) {
            yield { type: 'swap', indices: [i + 1, high] };
            await swap(i + 1, high);
        }
        
        const pivotIndex = i + 1;
        yield* quickSort(array, compare, swap, set, low, pivotIndex - 1);
        yield* quickSort(array, compare, swap, set, pivotIndex + 1, high);
    }
    yield { type: 'complete' };
}